package com.ruoyi.system.service.impl;

import java.util.List;

import com.ruoyi.system.annotation.UserContext;
import com.ruoyi.system.domain.vo.UserData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.system.mapper.TbProductInventoryMapper;
import com.ruoyi.system.domain.TbProductInventory;
import com.ruoyi.system.service.ITbProductInventoryService;

/**
 * 商品库存Service业务层处理
 * 
 * @author ruoyi
 * @date 2024-09-11
 */
@Service
public class TbProductInventoryServiceImpl implements ITbProductInventoryService 
{
    @Autowired
    private TbProductInventoryMapper tbProductInventoryMapper;

    /**
     * 查询商品库存
     * 
     * @param inventoryId 商品库存主键
     * @return 商品库存
     */
    @Override
    public TbProductInventory selectTbProductInventoryByInventoryId(Long inventoryId)
    {
        return tbProductInventoryMapper.selectTbProductInventoryByInventoryId(inventoryId);
    }

    /**
     * 查询商品库存列表
     * 
     * @param tbProductInventory 商品库存
     * @return 商品库存
     */
    @Override
    public List<TbProductInventory> selectTbProductInventoryList(TbProductInventory tbProductInventory)
    {
        UserData userData = UserContext.getUserData();
//        数据库中数据写反了（storeid是商家ID，merchantid是店铺ID）
        tbProductInventory.setMerchantId((long)userData.getMerchantId());
        tbProductInventory.setStoreId((long)userData.getStoreId());
//        System.out.println("tbProductInventory:-------"+tbProductInventory);
        try {
            return tbProductInventoryMapper.selectTbProductInventoryList(tbProductInventory);
        }finally {
            UserContext.clear();
        }
    }

    /**
     * 新增商品库存
     * 
     * @param tbProductInventory 商品库存
     * @return 结果
     */
    @Override
    public int insertTbProductInventory(TbProductInventory tbProductInventory)
    {
        UserData userData = UserContext.getUserData();
        tbProductInventory.setMerchantId((long)userData.getMerchantId());
        tbProductInventory.setStoreId((long)userData.getStoreId());
        try {
            return tbProductInventoryMapper.insertTbProductInventory(tbProductInventory);
        }finally {
            UserContext.clear();
        }

    }

    /**
     * 修改商品库存
     * 
     * @param tbProductInventory 商品库存
     * @return 结果
     */
    @Override
    public int updateTbProductInventory(TbProductInventory tbProductInventory)
    {
        return tbProductInventoryMapper.updateTbProductInventory(tbProductInventory);
    }

    /**
     * 批量删除商品库存
     * 
     * @param inventoryIds 需要删除的商品库存主键
     * @return 结果
     */
    @Override
    public int deleteTbProductInventoryByInventoryIds(Long[] inventoryIds)
    {
        return tbProductInventoryMapper.deleteTbProductInventoryByInventoryIds(inventoryIds);
    }

    /**
     * 删除商品库存信息
     * 
     * @param inventoryId 商品库存主键
     * @return 结果
     */
    @Override
    public int deleteTbProductInventoryByInventoryId(Long inventoryId)
    {
        return tbProductInventoryMapper.deleteTbProductInventoryByInventoryId(inventoryId);
    }
}
